package com.company.project.dao;

import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserDao{

    @Insert("INSERT INTO user (name, pwd, sex, age, love, phone, email) VALUES (#{name}, #{pwd}, #{sex}, #{age}, #{love}, #{phone}, #{email});")
    void save(User user);

    @Delete("delete form user where id = #{id}")
    void deleteById(Integer id);

    @Update("UPDATE user SET name = #{name}, pwd = #{pwd}, sex = #{sex}, age =  #{age}, love =  #{love}, phone = #{phone}, email = #{email} WHERE id = #{id};")
    void update(User user);

    @Select("select * from user where id = #{id}")
    User findById(Integer id);

    @Select("select * from user where name = #{name} and pwd = #{pwd}")
    User login(User user);

    @Select({"<script>","select * from user where 1=1",
            "<if test=\"name!=null and name!=''\">" ,
            "and name like concat('%',#{name},'%')" ,
            "</if>","</script>"})
    List<User> findAll(@Param("name") String name);
}